package com.tudouji.project.customer.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.customer.domain.CustomerBalance;
import com.tudouji.project.customer.service.ICustomerBalanceService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 客户余额Controller
 * 
 * @author tudouji
 * @date 2023-11-03
 */
@RestController
@RequestMapping("/customer/balance")
public class CustomerBalanceController extends BaseController
{
    @Autowired
    private ICustomerBalanceService customerBalanceService;

    /**
     * 查询客户余额列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CustomerBalance customerBalance)
    {
        startPage();
        List<CustomerBalance> list = customerBalanceService.selectCustomerBalanceList(customerBalance);
        return getDataTable(list);
    }

    /**
     * 导出客户余额列表
     */
    @Log(title = "客户余额", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CustomerBalance customerBalance)
    {
        List<CustomerBalance> list = customerBalanceService.selectCustomerBalanceList(customerBalance);
        ExcelUtil<CustomerBalance> util = new ExcelUtil<CustomerBalance>(CustomerBalance.class);
        return util.exportExcel(list, "balance");
    }

    /**
     * 获取客户余额详细信息
     */
    @PreAuthorize("@ss.hasPermi('customer:balance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(customerBalanceService.selectCustomerBalanceById(id));
    }

    /**
     * 新增客户余额
     */
    @PreAuthorize("@ss.hasPermi('customer:balance:add')")
    @Log(title = "客户余额", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerBalance customerBalance)
    {
        return toAjax(customerBalanceService.insertCustomerBalance(customerBalance));
    }

    /**
     * 修改客户余额
     */
    @PreAuthorize("@ss.hasPermi('customer:balance:edit')")
    @Log(title = "客户余额", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerBalance customerBalance)
    {
        return toAjax(customerBalanceService.updateCustomerBalance(customerBalance));
    }

    /**
     * 删除客户余额
     */
    @PreAuthorize("@ss.hasPermi('customer:balance:remove')")
    @Log(title = "客户余额", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(customerBalanceService.deleteCustomerBalanceByIds(ids));
    }
}
